package org.shopen.ai.puremvc.view.domain.cities
{
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	import org.shopen.ai.puremvc.ApplicationConstants;
	import org.shopen.ai.puremvc.model.domain.cities.CountryProxy;
	import org.shopen.ai.puremvc.view.domain.cities.components.CountryMap;
	import org.un.cava.birdeye.ravis.graphLayout.data.IGraph;

	public class CountryMapMediator extends Mediator
	{
		public static const NAME : String = "CountryMapMediator";
		
		private var _id : String = "";
		public function get id() : String
		{
			return _id;
		}
		public function set id(value : String) : void
		{
			_id = value;
		}
		
		protected function get countryMap() : CountryMap
		{
			var result : CountryMap = viewComponent as CountryMap;
			return result;
		}
		
		public function CountryMapMediator(id:String, viewComponent:CountryMap=null)
		{
			super(CountryMapMediator.NAME + id, viewComponent);
			this.id = id;
		}
		
		override public function getMediatorName():String
		{
			return CountryMapMediator.NAME + id;
		}
		
		override public function listNotificationInterests():Array
		{
			return [CountryProxy.COUNTRY_GRAPH_LOADED,
					CountryProxy.COUNTRY_GRAPH_LOAD_FAILED];
		}
		
		override public function handleNotification(notification:INotification):void
		{
			var type : String = notification.getType();
			if (type != this.id)
			{
				return;
			}
			var name : String = notification.getName();
			switch (name)
			{
				case CountryProxy.COUNTRY_GRAPH_LOADED:
					var graph : IGraph = notification.getBody() as IGraph;
					countryMap.graph = graph;
					break;
				case CountryProxy.COUNTRY_GRAPH_LOAD_FAILED:
					sendNotification(ApplicationConstants.GENERAL_ERROR, "Load map data failed!");
					break;
			}
		}
	}
}